import request from '@/utils/request/index'
import type { MenuParams, PermissionResponseData } from './type'
enum API {
  ALLPERMISSION_URL = '/admin/acl/permission',
  ADDMENU_URL = '/admin/acl/permission/save',
  UPDATEMENU_URL = '/admin/acl/permission/update',
  REMOVEMENU_URL = '/admin/acl/permission/remove'
}

export const reqAllMenuList = () =>
  request.get<PermissionResponseData>(`${API.ALLPERMISSION_URL}`)

export const reqAddOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request.put<null>(`${API.UPDATEMENU_URL}`, data)
  } else {
    return request.post<null>(`${API.ADDMENU_URL}`, data)
  }
}

export const reqRemoveMenu = (id: number) =>
  request.delete<null>(`${API.REMOVEMENU_URL}/${id}`)
